<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>
<!DOCTYPE>
<HTML>
<head>
    <!-- 引入通用js、css文件(xiaogq) -->
    <meta name="decorator" content="default"/>
    <!-- style-->
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/system/organization/role/role_data.css"/>
    <script type="text/javascript">
        $(document).ready(function(){
            //启用
            $("a[name='save']").bind("click",function(){
                var reodata = "";
                $("tr[changed='1']").each(function(){
                    var thisval =  $(this).attr("eid") + "=",operInfo = "";
                    var trNode = $(this).find("select[name='reoSelect']");
                    trNode.each(function(index,node){
                        operInfo += ($(this).attr("oid")+"_"+$(this).val());
                        if(index != (trNode.length -1)){
                            operInfo += ";"
                        }
                    });
                    reodata = reodata + thisval +operInfo + "&";
                });
                //console.log("reodata===",reodata);
                if(reodata != ""){
                    $.ajax({
                        url: "${ctx}/"+Constants.updateRoleOperationPmsUrl,
                        data: {
                            reodata : reodata,
                            roleid : $("#roleid").val()
                        },
                        type: 'POST',
                        success: function(data){
                            var flag = data.flag;
                            if(!flag){
                                alert("保存角色实体操作权限失败!");
                            }
                            parent.closeTab();
                        },
                        error: function() {
                            alert("保存角色实体操作权限错误!");
                        }
                    });
                }else{
                    parent.closeTab();
                }
            });

            $("select[name='reoSelect']").bind("change",function(){
                $(this).parents("tr").attr("changed","1");
            });

            //全部启用
            $("a[name='enableAll']").bind("click",function(){
                $("select[name='reoSelect'] option[name='reoUse']").attr("selected",true);
                $("select[name='reoSelect']").trigger("change");
            });

            //全部取消
            $("a[name='disableAll']").bind("click",function(){
                $("select[name='reoSelect'] option[name='reoNone']").attr("selected",true);
                $("select[name='reoSelect']").trigger("change");
            });

            //快捷操作 - 纵向
            $("select[name^='allentity_']").bind("change",function(){
                var thisval = $(this).val();
                if(thisval != ""){
                    var thisoid = $(this).attr("name").split("_")[1];
                    $("select[oid='"+thisoid+"'] option[value='"+thisval+"']").attr("selected",true);
                    $("tr[changed]").attr("changed",'1');
                }
            });
            //快捷操作 - 横向
            $("select[name='alloperation']").bind("change",function(){
                var thisval = $(this).val();
                if(thisval != ""){
                    $(this).parents("tr").find("select[canset] option[value='"+thisval+"']").attr("selected",true);
                    $(this).parents("tr").attr("changed","1");
                }
            });

        })
    </script>
</head>
<body>
<div id="buttonArray" class="button_list">
    <%--<c:if test="${!isAdmin }">--%>
        <a href="javascript:;" name="save">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_SAVE.png"></span>
                <span name="buTitle">保存</span>
            </span>
        </a>
    <%--</c:if>--%>
    <a href="javascript:;" onclick="javascript:parent.closeTab();">
        <span class="span_button">
            <span><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
            <span name="buTitle" title="">取消</span>
        </span>
    </a>
    <a href="javascript:;" name="enableAll">
        <span class="span_button">
            <span><img src="${ctx}/image/common/operation/oper_enableAll.png"></span>
            <span name="buTitle" title="">全部启用</span>
        </span>
    </a>
    <a href="javascript:;" name="disableAll">
        <span class="span_button">
            <span><img src="${ctx}/image/common/operation/oper_disableAll.png"></span>
            <span name="buTitle" title="">全部停用</span>
        </span>
    </a>
</div>

<div class="content-wrap" style="padding:5px 0 5px 0.5%;width:99.5%;">
    <input type="hidden" id="roleid" value="${roleid}"/>
    <table class="table-report" cellpadding="0" cellspacing="0" style="width:85%;margin:0 0 10px 0;">
        <c:if test="${not empty operPmsList }">
            <c:forEach var="reo" items="${operPmsList}" varStatus="v">
                <tr eid="${reo.entityId }"
                        <c:if test="${v.index%2 == 0}">
                            <c:choose>
                                <c:when test="${v.index==0 }">class="firstTh"</c:when>
                                <c:otherwise>class="tableOdd"</c:otherwise>
                            </c:choose>
                        </c:if>
                    <c:if test="${!v.first && v.index!=1 }">changed="0"</c:if>>
                    <td width="15%" style="color:#333;">${reo.entityName }</td>
                    <c:forEach var="reomap" items="${reo}">
                        <c:if test="${reomap.key ne 'entityId' && reomap.key ne 'entityName'}">
                            <td <c:if test="${reomap.key eq '002N89I711Um' || reomap.key eq '002N89IKZt8c' }" >style="display: none;"</c:if>>
                                <c:if test="${v.first }">
                                    ${reomap.value }
                                </c:if>
                                <c:if test="${!v.first }">
                                    <c:if test="${reo.entityId == '' }">
                                        <select name="allentity_${reomap.key }" class="filter-select">
                                            <option value=""></option>
                                            <option name="reoNone" value="0">无</option>
                                            <option name="reoUse" value="1">启用</option>
                                        </select>
                                    </c:if>
                                    <c:if test="${reo.entityId != '' }">
                                        <select class="filter-select"  oid="${reomap.key }" name="reoSelect" <c:if test="${reomap.key ne '9' && reomap.key ne '10' }" >canset=true</c:if> >
                                            <option name="reoNone" value="0">无</option>
                                            <c:if test="${reomap.value ne 'noenable'}">
                                                <option name="reoUse" value="1" <c:if test="${reomap.value eq 'enable' }" >selected="selected"</c:if>>启用</option>
                                            </c:if>
                                        </select>
                                    </c:if>
                                </c:if>
                            </td>
                        </c:if>
                    </c:forEach>
                    <td>
                        <c:if test="${!v.first && reo.entityId != '' }">
                            <select name="alloperation" class="filter-select">
                                <option value=""></option>
                                <option name="reoNone" value="0">无</option>
                                <option name="reoUse" value="1">启用</option>
                            </select>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </c:if>
    </table>
</div>
</body>
</html>
